<template>
    <div class="box-column">
        <ux-header-search ref="searchHeader" v-bind="enquiryData" :btnsData="{ permissionsData }"
            @search="onQueryClick"></ux-header-search>
        <div class="box-flex1 table">
            <vxe-grid v-bind="tableConfig" :data="dataStore.data" :columns="table.columns">
                <template v-slot:operate="{ row }">
                    <ux-btn-group :btns="table.btns" :data="{ row, permissionsData }"></ux-btn-group>
                </template>
            </vxe-grid>
        </div>
        <div class="pagination-el box-row box-center-end">
            <el-pagination @size-change="onSizeChange" @current-change="onCurrentChange"
                :current-page="dataStore.proxy.page" :page-size="dataStore.proxy.pageSize" :page-sizes="dataStore.pageSizes"
                :total="dataStore.pagination.total" :layout="'total, sizes, prev, pager, next, jumper'"></el-pagination>
        </div>
        <dialogForm ref="dialogForm" @submitSuccess="onSubmitSuccess" @closeDialog="onCloseDialog"></dialogForm>
    </div>
</template>

<script  lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { Action } from 'vuex-class';
import { mixinTableStore } from '@/mixin/table/Store';
import { mixinTableHeader } from '@/mixin/table/Header';
import { mixinTableOperation } from '@/mixin/table/Operation';
import { mixinDialogFormParent } from '@/mixin/dialog/FormParent';
import { mixinTabPage } from '@/mixin/tab/Page';
import { mixinAccess } from '@/mixin/Access';
import dialogForm from './Edit.vue';
@Component({
    name: 'scripAuthDoorTable',
    mixins: [
        mixinTableStore,
        mixinTableHeader,
        mixinTableOperation,
        mixinDialogFormParent,
        mixinTabPage,
        mixinAccess
    ],
    components: {
        dialogForm
    }
})
export default class scripAuthDoorTable extends Vue {
    @Action('equipmentCard/scripAuthDoorList') getList: any;
    @Action('equipmentCard/scripAuthDoorDelete') itemDel: any;
    infoData: any = {};
    editInit({ data }) {
        const me = this as any;
        me.infoData = data;
        me.lodaByDefaultParams({ scrip_sn: data.member_sn });
    }
    dataStore: any = {
        proxy: {
            autoLoad: false
        }
    };

    table: any = {
        btns: [
            {
                label: '删除',
                condition: [
                    'permissionsData.authDelete'
                ],
                handleClick: (this as any).onDelClick
            },
            {
                condition: [
                    'permissionsData.status',
                    function ({ row }) {
                        return row.status == 1;
                    }
                ],
                label: '停用',
                handleClick: this.onDisablesClick
            },
            {
                condition: [
                    'permissionsData.status',
                    function ({ row }) {
                        return row.status == 2;
                    }
                ],
                label: '启用',
                handleClick: this.onEnablementClick
            }
        ],
        // 列配置
        columns: [
            {
                fixed: 'left',
                width: 70,
                type: 'seq',
                title: '序号'
            },
            {
                fixed: 'left',
                width: 180,
                title: '门禁名称',
                field: 'door_name'
            },
            {
                width: 200,
                title: '门禁guid',
                field: 'door_guid'
            },
            {
                width: 120,
                title: '在线状态',
                field: 'door_status',
                formatter: function ({ cellValue }) {
                    return ['', '在线', '离线'][cellValue];
                },
                className: function ({ row }) {
                    return ['', 'green ', 'red'][row.door_status];
                }
            },
            {
                width: 120,
                title: '授权状态',
                field: 'status',
                formatter: function ({ cellValue }) {
                    return ['', '启用', '禁用'][cellValue];
                },
                className: function ({ row }) {
                    return ['', 'green', 'red'][row.status];
                }
            },
            {
                width: 120,
                title: '下发状态',
                field: 'scrip_down',
                formatter: function ({ cellValue }) {
                    return ['', '下发成功', '等待下发', '下发失败'][cellValue];
                },
                className: function ({ row }) {
                    return ['', 'green', '', 'red'][row.scrip_down];
                }
            },
            {
                width: 150,
                title: '下发时间',
                field: 'down_at',
                formatter: function ({ row }) {
                    return row.scrip_down == 2 ? '' : row.down_at;
                }
            },
            {
                title: '备注',
                field: 'remark',
                formatter: function ({ row }) {
                    return row.scrip_down == 2 ? '' : row.remark;
                }
            },
            {
                showOverflow: 'ellipsis',
                fixed: 'right',
                slots: { default: 'operate' },
                title: '操作',
                width: 160
            }
        ]
    };
    // 查询头配置
    enquiryData: any = {
        fields: [
            {
                field: 'door_name',
                label: '门禁名称'
            },
            {
                field: 'door_guid',
                label: '门禁guid'
            }
        ],
        btns: [
            {
                label: '添加',
                class: 'btn-blue',
                condition: [
                    'permissionsData.authAdd'
                ],
                icon: 'el-icon-plus',
                handleClick: (this as any).onAddInitClick
            }
        ]
    };
    onAddInitClick() {
        const me = this as any;
        me.setDialogValue('selectItem', me.infoData);
        me.onAddClick();
    }

    @Action('parkTenantCard/status') confirmAction: any;
    // 启用
    onEnablementClick({ row }: any) {
        const me = this as any;
        me.confirmMsg({ scrip_port_sn: row.scrip_port_sn, status: 1 }, '启用此卡');
    }
    // 停用
    onDisablesClick({ row }: any) {
        const me = this as any;
        me.confirmMsg({ scrip_port_sn: row.scrip_port_sn, status: 2 }, '停用此卡');
    }
}
</script>
